package com.zzh.lib.recorder.whole.editVideo.adpaters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.zzh.lib.recorder.R;

import androidx.recyclerview.widget.RecyclerView;

public class PasterAdapter extends RecyclerView.Adapter<PasterAdapter.ViewHolder> {

    private Context context;
    private int[] imgList;

    private int[] imagesGif = new int[]{R.raw.aini};

    public PasterAdapter(Context context, int[] imgList) {
        this.context = context;
        this.imgList = imgList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_paster, parent, false));
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.pasterview.setImageResource(imgList[position]);
    }

    @Override
    public int getItemCount() {
        return imgList == null ? 0 : imgList.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView pasterview;

        public ViewHolder(View itemView) {
            super(itemView);
            pasterview = itemView.findViewById(R.id.pasterview);
            pasterview.setOnClickListener(this::onViewClicked);
        }

        public void onViewClicked(View view) {
            if (pasterItemSelectListener != null) {
                pasterItemSelectListener.pasterItemSelect(imgList[getLayoutPosition()], imagesGif[getLayoutPosition()]);
            }
        }
    }

    public interface PasterItemSelectListener {
        void pasterItemSelect(int resourseId, int gifId);
    }

    PasterItemSelectListener pasterItemSelectListener;

    public void setPasterItemSelectListener(PasterItemSelectListener pasterItemSelectListener) {
        this.pasterItemSelectListener = pasterItemSelectListener;
    }
}
